﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMS.DAL.Providers
{
    public class OrderItemProvider : ProviderBase<OrderItem,OrderItemSearchCriteria>
    {
        public override void Insert(OrderItem item)
        {
            OrderItem x = new OrderItem();
            x.ItemCount = item.ItemCount;
            x.OrderID = item.OrderID;
            x.StockItemID = item.StockItemID;
            x.UnitPrice = item.UnitPrice;

            Context.OrderItems.AddObject(x);
            Context.SaveChanges();
            item.ID = x.ID;
        }

        public override void Update(OrderItem updatedItem)
        {
            throw new NotImplementedException();
        }

        public override void Delete(int id)
        {
            throw new NotImplementedException();
        }

        public override OrderItem GetByID(int id)
        {
            throw new NotImplementedException();
        }

        public override List<OrderItem> Search(OrderItemSearchCriteria SearchCriteria)
        {
            throw new NotImplementedException();
        }

        public void DeleteByOrderID(int id)
        {
            var quary = (from oi in Context.OrderItems
                         where (oi.OrderID == id)
                         select oi).ToList();
            foreach (var item in quary)
            {
                Context.OrderItems.DeleteObject(item);
            }
            OrderProvider orderProv = new OrderProvider();
            orderProv.Delete(id);
        }
    }
}
